package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/*
 * @version 1.0
 * @Author yanjingren
 * @Date 2021/7/6
 * @Description com.atguigu.gulimall.order.vo
 */

/**
 * 订单确认页需要用到的数据
 */
@ToString
public class OrderConfirmVo {
    // 收货地址，ums_user_address
    private List<MemberAddressVo> address;
    // 所有选中的购物项
    private List<OrderItemVo> items;
    // 发票记录......

    // 优惠券信息
    private Integer integration;

    // 订单总额
//    private BigDecimal total;

    // 应付价格
//    private BigDecimal payPrice;

    // 是否有库存
    @Getter
    @Setter
    private Map<Long, Boolean> stocks;

    // TODO 订单防重令牌
    @Getter
    @Setter
    private String orderToken;

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public Integer getCount() {
        Integer i = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }
}
